<extend name="Public/base" />
<!--<link rel="stylesheet" type="text/css" href="__PUBLIC__/selectjs/demo.css"/>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/selectjs/themes/easydropdown.css"/>-->
<block name="main">
    <fieldset class="layui-elem-field">
        <legend>订单管理 - {:(isset($detail['id'])?'编辑':'新增')}订单</legend>
        <div class="layui-field-box">
            <form class="layui-form" action="">
                <if condition="isset($detail['id'])">
                    <input type="hidden" name="id" value="{$detail['id']}">
                </if>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 批次</label>
                    <div class="layui-inline">
                        <select name="batch" lay-verify="required">
                            <option value="0">选择批次</option>
                            <volist name="batch" id="vo">
                                <option value="{$key}" {:($detail['fid'] == $key?'selected':'')}>{$vo}</option>
                            </volist>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 姓名</label>
                    <div class="layui-inline">
                        <input type="text" name="userName" required value="{:(isset($detail['userName'])?$detail['userName']:'')}" lay-verify="required" placeholder="请输入客户姓名" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 手机号</label>
                    <div class="layui-inline">
                        <input type="text" name="userPhone" required value="{:(isset($detail['userPhone'])?$detail['userPhone']:'')}" lay-verify="required" placeholder="请输入客户手机号" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 代理</label>
                    <div class="layui-inline">
                        <select name="agent" lay-verify="required">
                            <option value="0">选择代理</option>
                            <volist name="agent" id="vo">
                                <option value="{$key}" {:($detail['fid'] == $key?'selected':'')}>{$vo}</option>
                            </volist>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 地区</label>
                    <div class="layui-input-inline">
                        <select name="province" class="state" lay-filter="state" lay-verify="required">
                            <option value="0">请选择</option>
                        </select>
                    </div>
                    <div class="layui-input-inline">
                        <select name="city" class="state" lay-filter="state" lay-verify="required">
                            <option value="0">请选择</option>
                        </select>
                    </div>
                    <div class="layui-input-inline">
                        <select name="district" class="state" lay-filter="state" lay-verify="required">
                            <option value="0">请选择</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 详细地址</label>
                    <div class="layui-input-block">
                        <input type="text" name="userAddress" required value="{:(isset($detail['userAddress'])?$detail['userAddress']:'')}" lay-verify="required" placeholder="请输入客户地址" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span>购买类型</label>
                    <div class="layui-inline">
                        <select name="buyType" lay-verify="required">
                            <option value="">购买类型</option>
                            <volist name="buyType" id="vo">
                                <option value="{$key}" {:($detail['buyType'] == $key?'selected':'')}>{$vo}</option>
                            </volist>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 购买数量</label>
                    <div class="layui-inline">
                        <input type="text" name="buyNumber" required value="{:(isset($detail['buyNumber'])?$detail['buyNumber']:'')}" lay-verify="required" placeholder="请输入购买数量" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span>是否付款</label>
                    <div class="layui-inline">
                        <select name="isPay" lay-verify="">
                            <option value="">是否付款</option>
                            <volist name="isPay" id="vo">
                                <option value="{$key}" {:($detail['isPay'] == $key?'selected':'')}>{$vo}</option>
                            </volist>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 付款总价</label>
                    <div class="layui-inline">
                        <input type="text" name="buyPrice" required value="{:(isset($detail['buyPrice'])?$detail['buyPrice']:'')}" lay-verify="required" placeholder="请输入购买单价" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"> 快递费</label>
                    <div class="layui-inline">
                        <input type="text" name="expressPrice" value="{:(isset($detail['expressPrice'])?$detail['expressPrice']:'0')}" placeholder="输入增加的快递费" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"> 破损重发</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="isRewire" lay-skin="switch" lay-text="破损|不是" {:((isset($detail['hide']) && $detail['hide']==1)?'checked':'')}>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"> 备注</label>
                    <div class="layui-input-block">
                        <input type="text" name="remarks" required value="{:(isset($detail['remarks'])?$detail['remarks']:'')}"  placeholder="请输入备注信息" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="admin-form">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </fieldset>
</block>
<block name="myScript">
    <if condition="isset($detail['id'])">
        <script>
            layui.use('form', function(){
                var form = layui.form();
                form.on('submit(admin-form)', function(data){
                    $.ajax({
                        type: "POST",
                        url: '{:U("edit")}',
                        data: data.field,
                        success: function(msg){
                            if( msg.code == 1 ){
                                parent.location.reload();
                            }else{
                                parent.layer.msg(msg.msg, {
                                    icon: 5,
                                    shade: [0.6, '#393D49'],
                                    time:1500
                                });
                            }
                        }
                    });
                    return false;
                });

            });
        </script>
        <else />
        <script>
            layui.use('form', function(){
                var form = layui.form();
                form.on('submit(admin-form)', function(data){
                    //console.log(data.field);
                    $.ajax({
                        type: "POST",
                        url: '{:U("add")}',
                        data: data.field,
                        success: function(msg){
                            if( msg.code == 1 ){
                                parent.location.reload();
                            }else{
                                parent.layer.msg(msg.msg, {
                                    icon: 5,
                                    shade: [0.6, '#393D49'],
                                    time:1500
                                });
                            }
                        }
                    });
                    return false;
                });
            });

            layui.use('form', function(){
                //如果有需要到镇的改改就可以实现
                var form = layui.form(),
                        layer = layui.layer,
                        $ = layui.jquery;
                var url =  '{:U("getArea")}'; //数据请求地址
                var province = "广东省"; //编辑需要的省
                var city = "广州市"; //编辑需要的市
                var district = "天河区"; //编辑需要的县/区
                getJSON(url,$("select[name='province']").closest("div"));
                form.on('select(state)', function(data){
                    $that = $(data.elem);
                    urls = url+"&id="+data.value;
                    getJSON(urls,$that.closest("div").next());
                });
                function getJSON(urls,even){
                    $.getJSON(urls, function(json){
                        var pid = 0;
                        var name = even.find("select").attr("name");
                        var select = "<select name=\"" + name + "\" lay-filter=\"state\">";
                        select += "<option value=\"0\">请选择 </option>";
                        $(json).each(function(){
                            select += "<option value=\"" + this.id + "\"";
                            if(province == this.value || city == this.value || district == this.value){
                                select += " selected=\"selected\" ";
                                pid = this.id;
                            }
                            select += ">" + this.value + "</option>";
                        });
                        select += "</select>";
                        even.html(select);
                        var nextName = even.next().find("select").attr("name");
                        even.next().html("<select name=\"" + nextName + "\" lay-filter=\"state\"><option value=\"0\">请选择 </option></select>");
                        form.render('select');
                        if(pid != 0){
                            getJSON(url+"?id="+pid,even.next());
                        }
                    });
                }
            });


        </script>
    </if>
</block>